from tortoise.models import Model
from tortoise import fields


# 古诗
class Poem(Model):
    id = fields.IntField(pk=True)
    name=fields.CharField(max_length=30)
    author=fields.CharField(max_length=30)
    dynasty=fields.CharField(max_length=30)
    content=fields.TextField()
    trans=fields.TextField()
    annotation=fields.TextField()
    appreciation=fields.TextField()
    background=fields.TextField()
    created_at = fields.DatetimeField()

    # 1对多关系

    # 多对多关系
    likes=fields.ManyToManyField('models.User', related_name='poems')


# 用户
class User(Model):
    id = fields.IntField(pk=True)
    username = fields.CharField(max_length=30, unique=True)
    password = fields.CharField(max_length=128)

    # 1对1关系
    user_info=fields.ForeignKeyField('models.UserInfo', related_name='user')


# 用户详细信息
class UserInfo(Model):
    id = fields.IntField(pk=True)
    username=fields.CharField(max_length=30, unique=True)
    gender=fields.CharField(max_length=5)
    phone=fields.CharField(max_length=11, unique=True)
    signature=fields.TextField()
    email=fields.CharField(max_length=50, unique=True)


# 用户创作的古诗
class Work(Model):
    id = fields.IntField(pk=True)
    name=fields.CharField(max_length=30)
    content=fields.TextField()
    created_at = fields.DatetimeField()

    # 1对多关系
    user=fields.ForeignKeyField('models.User', related_name='works')
    
